package com.soft.javase.day08.userlogin;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/27
 */
public class UserTest {
    public static void main(String[] args) {
        List<User> list = new ArrayList<>();
        list.add(new User("张三","123"));
        list.add(new User("李四","1234"));
        list.add(new User("王五","12345"));
        list.add(new User("赵六","123456"));

        System.out.println(login(list));
    }

    public static boolean login(List<User> list) {
        Scanner sc = new Scanner(System.in);
        boolean flag = false;
        A:for (int i = 0; i < 3; i++) {
            System.out.println("请输入用户名：");
            String username = sc.nextLine();
            System.out.println("请输入密码：");
            String password = sc.nextLine();
            for (User user : list) {
                if (Objects.equals(username, user.getUsername()) && Objects.equals(password, user.getPassword())) {
                    flag = true;
                    System.out.println("登陆成功！");
                    break A;
                }
            }
        }
        if (!flag){
            System.out.println("登录失败，三次机会已用完！");
        }
        return flag;
    }
}
